<?php 

class PhotogalleryPresenter extends BasePresenter{
	
	private $model;
	/**
	 * Start lifecycle presenter
	 *
	 * @return void
	 */
	protected function startup(){
		
		parent::startup();
		
		$this->model = PhotogalleryModel::getInstance();
	}

	/**
	 * Settings for all render
	 *
	 * @return void
	 */
	protected function beforeRender(){
		
		
	}
	
	public function boxHTML($id){
		
		$system = SystemModel::getInstance();
		$menuItem = $system->getMenuItemByName($id);
		
		$this->model = PhotogalleryModel::getInstance();
		
		$info = $this->model->getInfo($menuItem[0]["id_menu"]);
			
		foreach($info as &$i){
			$i["main"] = $this->model->getMainPhoto($i["id_photogallery"]);
			$i["link"] = $this->presenter->link("Photogallery:", array("id" => $id, "seo_title" => $i["seo_title"]));
		}
		
		$info = array_slice($info, 0, 3);
		
		$template = new Template();
		$template->registerFilter(new LatteFilter);
		$template->gallery = $info;
		$template->setFile(APP_DIR."/modules/Photogallery/templates/front/box.phtml");
		
		return $template;
	}
	
	/**
	 * Render default action
	 *
	 * @return void
	 */
	public function renderDefault($id){
		
		$seo_title = $this->getParam("seo_title");
		
		$this->template->id = $id;
		// zobrazeni fotogalerii
		if(empty($seo_title)){
			$menuItem = $this->system->getMenuItemByName($id);
	
			$info = $this->model->getInfo($this->id_menu);
			
			foreach($info as &$i){
				$i["main"] = $this->model->getMainPhoto($i["id_photogallery"]);
			}
			
			$this->template->add("info", $info);
		}
		// zobrazeni konkretni fotogalerie
		else{
			
			$gallery = $this->model->getPhotogalleryInfoByTitle($seo_title);
			$gallery["pictures"] = $this->model->getPictures($gallery["id_photogallery"]);

			// pridame do navigace
			$navigace = array(
							"address" => $address,
							"name" => $gallery["title"]
							);
			
			$this->addToNavigation($navigace);
			
			$this->template->gallery = $gallery;
		}
		

	}
	
	public function renderPhotogallery(){
		
	}
	
}

?>